package com.ohuang.apkpatch;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class FileCompare {

    public static boolean isSameFile2(String filePath1, String filePath2) {
        try {
            // 检查文件大小是否相同
            if (Files.size(Paths.get(filePath1)) != Files.size(Paths.get(filePath2))) {
                return false;
            }

            try (BufferedInputStream bis1 = new BufferedInputStream(new FileInputStream(filePath1));
                 BufferedInputStream bis2 = new BufferedInputStream(new FileInputStream(filePath2))) {

                int byte1, byte2;
                while ((byte1 = bis1.read()) != -1) {
                    byte2 = bis2.read();
                    if (byte1 != byte2) {
                        return false;
                    }
                }
                return true;
            }
        } catch (IOException e) {
            e.printStackTrace(); // 或者记录日志
            return false;
        }
    }
}
